package zd.cornermemory.utils;

import java.io.File;

/**
 * Created by Admin on 2021/8/23.
 */

public class FileUtil {
    /**
     * 判断文件大小
     *
     * @param file
     *            文件
     *            限制大小
     *            限制单位（B,K,M,G）
     * @return
     */
    public static boolean checkFileSize(File file) {
        long len = file.length();
        int size = 1;//
        String unit = "M";
        double fileSize = 0;
        if ("B".equals(unit.toUpperCase())) {
            fileSize = (double) len;
        } else if ("K".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1024;
        } else if ("M".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1048576;
        } else if ("G".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1073741824;
        }
        if (fileSize > size) {
            return false;
        }
        return true;
    }

}
